package com.spec.controller.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spec.config.Const;
import com.spec.services.system.dictionary.IDictionaryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import sys.basic.controller.BaseController;
import sys.basic.entity.PageData;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping(value="/dictionary")
public class DictionaryController extends BaseController{
	
	@Resource(name="dictionaryService")
	private IDictionaryService dictionaryService;
	
	@RequestMapping(value="/list")
	public ModelAndView find(){
		ModelAndView mv = this.getModelAndView();
		PageData pd = this.getPageData();
		PageInfo<PageData> dicts = null;
		PageHelper.startPage(Integer.parseInt(pd.getString("page")), Const.PAGE_NUMBER);
		try {
			List<PageData> res = dictionaryService.find(pd);
			dicts = new PageInfo<PageData>(res);
		} catch (Exception e) {
			e.printStackTrace();
		}
		mv.addObject("dicts",dicts.getList());
		mv.addObject("pd",pd);
		mv.setViewName("system/dictionary/dictionary_list");
		return mv;
	}
	
}
